<template>
  <div class="cartcontrol">
    <transition name="move">
      <div class="iconfont icon-remove_circle_outline" v-if="count>0" @click="updateFoodCount(false)">一</div>
    </transition>
    <div class="cart-count" v-if="count>0">{{count}}</div>
    <div class="iconfont icon-add_circle" @click="updateFoodCount(true)"></div>
  </div>
</template>


<script>
    export default {
      props: {
        food: Object
      },
      data () {
            return {
              count:''
            }
        },
      mounted(){

      },
      methods:{
        updateFoodCount(msg){
            if(msg){
              //从vuex中拿count
              this.$store.commit('add')
              this.count = this.$store.getters.count
            }else{
              this.$store.commit('remove')
              this.count = this.$store.getters.count
            }
        }


      }
    }
</script>
<style lang="stylus" rel="stylesheet/stylus">
  @import "../../static/css/mixins.styl"
  .cartcontrol
    font-size: 0
    .cart-decrease
      display: inline-block
      padding: 6px
      line-height: 24px
      font-size: 24px
      color: rgb(0, 160, 220)

    .icon-remove_circle_outline
      display: inline-block
      padding 6px
      line-height 24px
      font-size 24px
      color $green
      &.move-enter-active, &.move-leave-active
        transition all .5s
      &.move-enter, &.move-leave-to
        opacity 0
        transform translateX(10px) rotate(90deg)
    .cart-count
      display: inline-block
      vertical-align: top
      width: 12px
      padding-top: 6px
      line-height: 24px
      text-align: center
      font-size: 10px
      color: rgb(147, 153, 159)
    .icon-add_circle
      display: inline-block
      padding: 6px
      line-height: 24px
      font-size: 24px
      color $green
</style>

